﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace Scorpicore.MVC.Models
{
    [AttributeUsage(AttributeTargets.Property)]
    public class AvatarValidatorAttribute : ValidationAttribute
    {
        public AvatarValidatorAttribute()
        {
         
        }

        public override bool IsValid(object value)
        {
            HttpPostedFileBase file = (HttpPostedFileBase)value;
            if (file.ContentType == "image/gif"
                || (file.ContentType == "image/jpeg")
                || (file.ContentType == "image/png"))
            {
                if (file.ContentLength < 50000 
                    && file != null 
                    && file.ContentLength > 0)
                {
                    return true;
                }
            }

            return false;
        }
    }
}